package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.PapersAndBooks;
import com.ruoyi.business.service.IPapersAndBooksService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 论文著作Controller
 *
 * @author ruoyi
 * @date 2024-11-18
 */
@Api(tags = "论文著作管理",value = "论文著作管理", description = "论文著作管理，包括查询、新增、修改、删除等功能")
@RestController
@RequestMapping("/business/papersAndBooks")
public class PapersAndBooksController extends BaseController
{
    @Autowired
    private IPapersAndBooksService papersAndBooksService;

    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping("/importData")
    @ApiOperation(value = "导入数据", notes = "导入论文著作数据")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<PapersAndBooks> util = new ExcelUtil<PapersAndBooks>(PapersAndBooks.class);
        List<PapersAndBooks> userList = util.importExcel("论文著作数据",file.getInputStream(),1);
        String operName = getUsername();
        String message = papersAndBooksService.importData(userList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    @ApiOperation(value = "导出模板", notes = "导出论文著作数据模板")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<PapersAndBooks> util = new ExcelUtil<PapersAndBooks>(PapersAndBooks.class);
        util.importTemplateExcel(response, "论文著作数据","论文著作数据");
    }

    /**
     * 查询论文著作列表
     */
    @PreAuthorize("@ss.hasPermi('business:papersAndBooks:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询列表", notes = "查询论文著作列表")
    public TableDataInfo list(PapersAndBooks papersAndBooks)
    {
        startPage();
        List<PapersAndBooks> list = papersAndBooksService.selectPapersAndBooksList(papersAndBooks);
        return getDataTable(list);
    }

    /**
     * 导出论文著作列表
     */
    @PreAuthorize("@ss.hasPermi('business:papersAndBooks:export')")
    @Log(title = "论文著作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出数据", notes = "导出论文著作数据")
    public void export(HttpServletResponse response, PapersAndBooks papersAndBooks)
    {
        List<PapersAndBooks> list = papersAndBooksService.selectPapersAndBooksList(papersAndBooks);
        ExcelUtil<PapersAndBooks> util = new ExcelUtil<PapersAndBooks>(PapersAndBooks.class);
        util.exportExcel(response, list, "论文著作数据");
    }

    /**
     * 获取论文著作详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:papersAndBooks:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取详情", notes = "获取论文著作详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(papersAndBooksService.selectPapersAndBooksById(id));
    }

    /**
     * 新增论文著作
     */
    @PreAuthorize("@ss.hasPermi('business:papersAndBooks:add')")
    @Log(title = "论文著作", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增数据", notes = "新增论文著作")
    public AjaxResult add(@RequestBody PapersAndBooks papersAndBooks)
    {
        return toAjax(papersAndBooksService.insertPapersAndBooks(papersAndBooks));
    }

    /**
     * 修改论文著作
     */
    @PreAuthorize("@ss.hasPermi('business:papersAndBooks:edit')")
    @Log(title = "论文著作", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改数据", notes = "修改论文著作")
    public AjaxResult edit(@RequestBody PapersAndBooks papersAndBooks)
    {
        return toAjax(papersAndBooksService.updatePapersAndBooks(papersAndBooks));
    }

    /**
     * 删除论文著作
     */
    @PreAuthorize("@ss.hasPermi('business:papersAndBooks:remove')")
    @Log(title = "论文著作", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除数据", notes = "删除论文著作")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(papersAndBooksService.deletePapersAndBooksByIds(ids));
    }
}
